import { listProfession } from "@/api/system/profession";
import { listSemester } from "@/api/system/semester";

const state = {
  profession: [], // 专业列表
  semester: [], // 学期列表
};

const mutations = {
  SET_PROFESSION: ({ profession }, proData) => {
    profession = proData;
  },
  SET_SEMESTER: ({ semester }, semData) => {
    semester = semData;
  },
};

const actions = {
  // 设置专业列表
  setProfession({ commit }) {
    return new Promise((resolve, reject) => {
      listProfession()
        .then((res) => {
          resolve();
          commit("SET_PROFESSION", res.data);
        })
        .catch((err) => {
          reject(err);
        });
    });
  },
  // 设置学期列表
  removeDict({ commit }) {
    return new Promise((resolve, reject) => {
      listSemester()
        .then((res) => {
          resolve();
          commit("SET_SEMESTER", res.data);
        })
        .catch((err) => {
          reject(err);
        });
    });
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
